package com.aqie.haikang.dorm.controller;

import com.aqie.haikang.dorm.common.R;
import com.aqie.haikang.dorm.crontab.DynamicScheduleTask;
import com.aqie.haikang.dorm.entity.Cron;
import com.aqie.haikang.dorm.entity.HkEnter;
import com.aqie.haikang.dorm.entity.dto.HkEnterDTO;
import com.aqie.haikang.dorm.service.ICronService;
import com.aqie.haikang.dorm.service.IHkEnterService;
import com.ejlchina.okhttps.HTTP;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author aqie
 * @Date 2021/12/11 9:41
 * @desc
 */
@Slf4j
@RestController
@RequestMapping("hkEnter")
public class HkEnterController {
    @Autowired
    private IHkEnterService hkEnterService;

    @Autowired
    private ICronService cronService;

    @Autowired
    private DynamicScheduleTask scheduleTask;

    @Value("${baseUrl}")
    private String baseUrl;

    @GetMapping("refresh")
    public void refreshTask() {
        List<Cron> list = cronService.list();
        scheduleTask.refresh(list);
    }

    /**
     * 查询当天数据
     * @return
     */
    @GetMapping("getCurrentList")
    public R<List<HkEnterDTO>> getCurrentList(){
        List<HkEnterDTO> currentAll = hkEnterService.findCurrentAll();
        return R.ok(currentAll);
    }

    /**
     * 发送当天数据到服务器
     */
    @PostMapping("post")
    public R<Boolean> postData(){
        log.info("post url {}", baseUrl);
        return R.ok(hkEnterService.postData());
    }

}
